package com.credithc.customers.base.mapper;

import com.credithc.baseserv.core.mapper.BsBaseMapper;
import com.credithc.customers.base.po.CustomerExtendPo;
import com.credithc.customers.base.po.PreCustomerInfoPo;
import com.credithc.customers.base.vo.PreCustomerDetailVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhukai
 * @date 2018/11/29 13:47
 */
@Mapper
@Repository
public interface CustomerExtendMapper extends BsBaseMapper<CustomerExtendPo> {

    List<CustomerExtendPo> getCustomerUnifyInfo(@Param("preCustomerNo") String preCustomerNo, @Param("customerNo") String customerNo, @Param("systemSign") String systemSign, @Param("subSystemSign") String subSystemSign);

    @Select("select id,pre_customer_no preCustomerNo,customer_no customerNo,system_sign systemSign,sub_system_sign subSystemSign,create_time createTime,status,remark\n" +
            " from cust_extend where pre_customer_no=#{preCustomerNo} and status=#{status} and sub_system_sign=#{subSystemSign}")
    List<CustomerExtendPo> getRegisterInfoBySubSystemAndStatus(@Param("preCustomerNo") String preCustomerNo,@Param("subSystemSign") String subSystemSign,@Param("status") Integer status);

    @Select("select a.pre_customer_no preCustomerNo,a.customer_no customerNo,b.customer_name customerName\n" +
            " from cust_extend a join company_id_info b on a.customer_no = b.customer_no where a.pre_customer_no=#{preCustomerNo} and a.status=#{status} and a.sub_system_sign=#{subSystemSign}")
    List<PreCustomerDetailVo> getPreCustomerCompanyDetail(@Param("preCustomerNo") String preCustomerNo, @Param("subSystemSign") String subSystemSign, @Param("status") Integer status);

    @Select("select a.pre_customer_no preCustomerNo,a.customer_no customerNo,b.customer_name customerName\n" +
            " from cust_extend a join cust_id_info b on a.customer_no = b.customer_no where a.pre_customer_no=#{preCustomerNo} and a.status=#{status} and a.sub_system_sign=#{subSystemSign}")
    List<PreCustomerDetailVo> getPreCustomerPersonDetail(@Param("preCustomerNo") String preCustomerNo, @Param("subSystemSign") String subSystemSign, @Param("status") Integer status);

    @Select("select a.pre_customer_no preCustomerNo\n" +
            " from cust_pre_info a join cust_oauth_token b on a.pre_customer_no = b.pre_customer_no where a.contact_info=#{phone} and a.contact_type= '1' and b.register_status=#{status} and b.sub_system_id=#{subSystemSign}")
    List<PreCustomerInfoPo> getRegisterPreCustomerInfo(@Param("phone") String phone, @Param("subSystemSign") String subSystemSign, @Param("status") Integer status);

    @Select("select id,pre_customer_no preCustomerNo,customer_no customerNo,system_sign systemSign,sub_system_sign subSystemSign,create_time createTime,status from cust_extend\n" +
            "where pre_customer_no=#{preCustomerNo} and system_sign=#{systemSign} and status= 1 ORDER BY create_time ASC LIMIT 1")
    CustomerExtendPo getRegisterSystem(@Param("preCustomerNo") String preCustomerNo, @Param("systemSign") String systemSign);
}
